import axios from 'axios';
import qs from 'qs';

const actions={
    login({
        state
    },params={}){
        let bones = new Promise((resolve, reject) => {
            return axios.post(
                params.API || state.API.login, qs.stringify(Object.assign({}, params)
            )).then((res) => {
                if (res.data.result == "1") {
                    resolve(res.data);
                } else {
                    resolve(res.data);
                }
            }).catch((err)=>{
                reject(err.data);
            });
        });
        return bones;
    },
    loginOut({
        state
    },params={}){
        let bones = new Promise((resolve, reject) => {
            return axios.post(
                params.API || state.API.loginOut, qs.stringify(Object.assign({}, params)
            )).then((res) => {
                if (res.data.result == "1") {
                    resolve(res.data);
                } else {
                    resolve(res.data);
                }
            }).catch((err)=>{
                reject(err.data);
            });
        });
        return bones;
    },
    losePassWord({
        state
    },params={}){
        let bones = new Promise((resolve, reject) => {
            return axios.post(
                params.API || state.API.losePassWord, qs.stringify(Object.assign({}, params)
            )).then((res) => {
                if (res.data.result == "1") {
                    resolve(res.data);
                } else {
                    resolve(res.data);
                }
            }).catch((err)=>{
                reject(err.data);
            });
        });
        return bones;
    },
    register({
        state
    },params={}){
        let bones = new Promise((resolve, reject) => {
            return axios.post(
                params.API || state.API.register, qs.stringify(Object.assign({}, params)
            )).then((res) => {
                if (res.data.result == "1") {
                    resolve(res.data);
                } else {
                    resolve(res.data);
                }
            }).catch((err)=>{
                reject(err.data);
            });
        });
        return bones;
    },
    setUserInfo({
        state
    },params={}){
        let bones = new Promise((resolve, reject) => {
            return axios.post(
                params.API || state.API.setUserInfo, qs.stringify(Object.assign({}, params)
            )).then((res) => {
                if (res.data.result == "1") {
                    resolve(res.data);
                } else {
                    resolve(res.data);
                }
            }).catch((err)=>{
                reject(err.data);
            });
        });
        return bones;
    },
    queryValueByKeys({
        state
    },params={}){
        let bones = new Promise((resolve, reject) => {
            return axios.post(
                params.API || state.API.queryValueByKeys, qs.stringify(Object.assign({"paramKeys":"companyType"}, params)
            )).then((res) => {
                if (res.data.result == "1") {
                    resolve(res.data);
                } else {
                    resolve(res.data);
                }
            }).catch((err)=>{
                reject(err.data);
            });
        });
        return bones;
    },
    verifyCode({
        state
    },params={}){
        let bones = new Promise((resolve, reject) => {
            return axios.post(
                params.API || state.API.verifyCode, qs.stringify(Object.assign({}, params)
            )).then((res) => {
                if (res.data.result == "1") {
                    resolve(res.data);
                } else {
                    resolve(res.data);
                }
            }).catch((err)=>{
                reject(err.data);
            });
        });
        return bones;
    },
    initValCode({
        state
    },params={}){
        let bones = new Promise((resolve, reject) => {
            return axios.post(
                params.API || state.API.initValCode, qs.stringify(Object.assign({}, params)
            )).then((res) => {
                if (res.data.result == "1") {
                    resolve(res.data);
                } else {
                    resolve(res.data);
                }
            }).catch((err)=>{
                reject(err.data);
            });
        });
        return bones;
    },
    modifyUserInfo({
        state
    },params={}){
        let bones = new Promise((resolve, reject) => {
            return axios.post(
                params.API || state.API.modifyUserInfo, qs.stringify(Object.assign({}, params)
            )).then((res) => {
                if (res.data.result == "1") {
                    resolve(res.data);
                } else {
                    resolve(res.data);
                }
            }).catch((err)=>{
                reject(err.data);
            });
        });
        return bones;
    }
     
    
}
export default {
    actions
};
